package com.ny20231079080.dao.Impl;

import com.ny20231079080.dao.OrderDao;
import com.ny20231079080.entity.Orders;
import homework.six.DbUntil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class OrderDaoImpl implements OrderDao {
    private DbUntil dbUntil = new DbUntil();
    @Override
    public int insertOrder(Orders order) throws SQLException, ClassNotFoundException {
        Connection  con = dbUntil.getCon();
        String sql = "insert into orders(student_id,product_id,number,total_price) values(?,?,?,?)";
        PreparedStatement preparedStatement = con.prepareStatement(sql);
        preparedStatement.setInt(1, order.getStudent_id());
        preparedStatement.setInt(2, order.getProduct_id());
        preparedStatement.setInt(3, order.getNumber());
        preparedStatement.setDouble(4, order.getTotal_price());
        return preparedStatement.executeUpdate();

    }
}
